package cn.lsc.service.impl;

import cn.lsc.enums.GlobaEnums;
import cn.lsc.result.JSONResult;
import cn.lsc.service.ITokenService;
import cn.lsc.util.AssertUtil;
import cn.lsc.util.StrUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.concurrent.TimeUnit;

@Service
public class TokenServiceImpl implements ITokenService {

    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;
    @Override
    public String  createToken(Long courseId) {
        AssertUtil.isNotNull(courseId, GlobaEnums.PARAM_IS_NULL_ERROR);
        //使用工具类生成六位token
        String token = StrUtils.getComplexRandomString(6);
        Long loginId=3L;
        String key="token:"+loginId+":"+courseId;
        redisTemplate.opsForValue().set(key,token,10, TimeUnit.MINUTES);

        return token;
    }
}
